$.fn.dataTableExt.oPagination.four_button = {
    "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
    {
        nFirst = document.createElement( 'span' );
        nPrevious = document.createElement( 'span' );
        nNext = document.createElement( 'span' );
        nLast = document.createElement( 'span' );
          
        nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
        nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
        nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
        nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
          
        nFirst.className = "paginate_button first";
        nPrevious.className = "paginate_button previous";
        nNext.className="paginate_button next";
        nLast.className = "paginate_button last";
          
        nPaging.appendChild( nFirst );
        nPaging.appendChild( nPrevious );
        nPaging.appendChild( nNext );
        nPaging.appendChild( nLast );
          
        $(nFirst).click( function () {
            oSettings.oApi._fnPageChange( oSettings, "first" );
            fnCallbackDraw( oSettings );
        } );
          
        $(nPrevious).click( function() {
            oSettings.oApi._fnPageChange( oSettings, "previous" );
            fnCallbackDraw( oSettings );
        } );
          
        $(nNext).click( function() {
            oSettings.oApi._fnPageChange( oSettings, "next" );
            fnCallbackDraw( oSettings );
        } );
          
        $(nLast).click( function() {
            oSettings.oApi._fnPageChange( oSettings, "last" );
            fnCallbackDraw( oSettings );
        } );
          
        /* Disallow text selection */
        $(nFirst).bind( 'selectstart', function () { return false; } );
        $(nPrevious).bind( 'selectstart', function () { return false; } );
        $(nNext).bind( 'selectstart', function () { return false; } );
        $(nLast).bind( 'selectstart', function () { return false; } );
    },
     
     
    "fnUpdate": function ( oSettings, fnCallbackDraw )
    {
        if ( !oSettings.aanFeatures.p )
        {
            return;
        }
          
        /* Loop over each instance of the pager */
        var an = oSettings.aanFeatures.p;
        for ( var i=0, iLen=an.length ; i<iLen ; i++ )
        {
            var buttons = an[i].getElementsByTagName('span');
            if ( oSettings._iDisplayStart === 0 )
            {
                buttons[0].className = "paginate_disabled_previous";
                buttons[1].className = "paginate_disabled_previous";
            }
            else
            {
                buttons[0].className = "paginate_enabled_previous";
                buttons[1].className = "paginate_enabled_previous";
            }
              
            if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
            {
                buttons[2].className = "paginate_disabled_next";
                buttons[3].className = "paginate_disabled_next";
            }
            else
            {
                buttons[2].className = "paginate_enabled_next";
                buttons[3].className = "paginate_enabled_next";
            }
        }
    }
};

function accountTable(roles){

	$('.accountDataTable').dataTable( {
    	"bJQueryUI":true,
    	"sPaginationType": "four_button",
    	"iDisplayLength": 5,
    	"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
    	"sScrollY": 200,
        'bProcessing': false,
        'bServerSide': false,
        'sAjaxSource': '/sales/s/getAllAccounts',
        'aoColumns': [
            { 'mData': 'id' ,"bSearchable": false,"bSortable": false },
            { 'mData': 'isFollowed',"bSearchable": false,"bSortable": false,"sWidth": "4%" },
            { 'mData': 'accountName' },
            { 'mData': 'companyName' },
            { 'mData': 'accountOwner',"bSearchable": false,"bSortable": false }
            
        ],
        "aoColumnDefs": [
            {"aTargets": [0],"mData": null,"mRender": function (data, type, full) {
            	var urls=null;
        	    var userRoles=roles;
        	    if(userRoles.indexOf("accountView")!=-1){
        	    	urls="<a href='viewAccount?id=" + data + "'><img src='../images/info.png' title='View Account'/> </a>";
        	    }
        	    if(userRoles.indexOf("accountEdit")!=-1){
        	    	urls+="<a href='edit-account?id=" + data + "'><img src='../images/edit.png' title='Edit Account'/> </a>";
        	    }
        	    if(userRoles.indexOf("accountDelete")!=-1){
        	    	urls+="<a href='delete-account?id=" + data + "'><img src='../images/delete.png' title='Delete Account'/> </a>";
        	    }
   				return urls;
            }}
            ,
	         {
		           "aTargets": [1],
		           "mData": null,
		           "mRender": function (data, type, full) {
		        	   				var userRoles=roles;
		        	   				var followSplit=data.split("/");
		        	   				var leadId=followSplit[0];
		        	   				var isFollowed=followSplit[1];
		        	   				if(isFollowed=="true"){
		        	   					return "<a><img src='../images/icon-followed.png'/> </a>";
		        	   				}
		        	   				else{
		        	   					if(userRoles.indexOf("accountFellow")!=-1){
			        	   					return "<a href='followAccount?accountId=" + leadId + "'><img src='../images/icon-follow.png' title='Follow'/> </a>";
			        	   					
		        	   					}
		        	   				}
		                       }
		         }
        ]
    } ); 
} ;
